﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace ControlsTest
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
        // Valid characters for category names: a->z, A->Z, 0->9, space and .-$@!{}()[]
        private Regex reg = new Regex(@"^[a-zA-Z0-9 \.\-\$\@\!\{\}\(\)\[\]]{0,}$");

        private void comboBox1_Leave(object sender, EventArgs e)
        {
            if (!reg.IsMatch(comboBox1.Text))
            {
                this.Focus();
                MessageBox.Show(@"You have used illegal characters in the category name. In general, the category name must use only characters that are valid in a Windows file name: A-Z, a-z, 0-9, space, and the characters: .-$@!{}()[]",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        protected override void OnLeave(EventArgs e)
        {
            //if (!reg.IsMatch(comboBox1.Text))
            //{
            //    this.Focus();
            //    MessageBox.Show(@"You have used illegal characters in the category name. In general, the category name must use only characters that are valid in a Windows file name: A-Z, a-z, 0-9, space, and the characters: .-$@!{}()[]",
            //        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}
            base.OnLeave(e);
        }

    }
}
